stage.create_grid_overlay(50, 'greenyellow')
size = .3
planet = codesters.Sprite("mars", -200, -200)
planet.set_size(.4)
planet.collision_off()
stop1 = codesters.Sprite("codester", -100, -100)
stop1.set_size(size)
stop2 = codesters.Sprite("codester", 150, -100)
stop2.set_size(size)
stop3 = codesters.Sprite("codester", 150, 100)
stop3.set_size(size)
stop4 = codesters.Sprite("codester", -150, 200)
stop4.set_size(size)
stage.set_background("space")
sprite = codesters.Sprite("ufo")
sprite.set_size(0.4)
sprite.go_to(-200, -200)
sprite.pen_down()
sprite.glide_to(-100, -100)
def collision(sprite, hit_sprite):
hit_sprite.hide()
# add any other actions...
sprite.event_collision(collision)
sprite.set_speed(2)
sprite.glide_to(150, -100)
sprite.glide_to(150, 100)
t = codesters.Teacher()
glides = t.get_parameters_for_function('glide_to')
turns = t.get_parameters_for_function('turn_left')
try:
tval1 = int(glides[-1][0])
dev_x = abs(-150 - tval1)
except:
tval1 = "DNE"
dev_x = "DNE"
try:
tval2 = int(glides[-1][1])
dev_y = abs(200 - tval2)
except:
tval2 = "DNE"
dev_y = "DNE"
dev_hor = 61
t1 = TestObjective()
t1.add_success(dev_x<= dev_hor and len(glides) >= 4, "Great job!")
t1.add_failure(tval1 == "DNE" or len(glides) < 4, "There's the Codester! Now add a Glide To command.")
t1.add_failure(tval1 > 250 or tval1 < -250, "Oops! You moved your sprite off the stage!")
t1.add_failure(dev_x > dev_hor and len(glides) >= 4, "Change your x-coordinate to get closer to the sprite!")
dev_vert = 48
t2 = TestObjective()
t2.add_success(dev_y <= dev_vert and len(glides) >= 4, "Great job!")
t2.add_failure(tval2 == "DNE" or len(glides) < 4, "Did you add a Glide To command?")
t2.add_failure(tval2 > 250 or tval2 < -250, "Oops! You moved your sprite off the stage!")
t2.add_failure(dev_y > dev_vert and len(glides) >= 4, "Change your y-coordinate to get closer to the sprite!")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
# tester = TestManager()
# tester.add_test_list([ t1])
# tester.run_tests()
# tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)